// pages/manage1/manage1.js 
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 顶部进度条内容
    canArr:[
      {
        num:'2',
        progress:'0.6',
        text:'新增客户'
      },
      {
        num: '2',
        progress: '0.3',
        text: '当天跟进'
      },
      {
        num: '2',
        progress: '0.8',
        text: '客户总数'
      },
      {
        num: '2',
        progress: '1',
        text: '本月销售额'
      }
    ],
    // 顶部进度条颜色
    colorArr: ['#05b510', '#9b70fe', '#fcbe43','#05b510'],
    // 中间推荐部分
    nav:[
      {
        img:'/images/tabbar1.png',
        text:'推名片',
        path:'',
      },
      {
        img: '/images/tabbar1.png',
        text: '推产品',
        path: '',
      },
      {
        img: '/images/tabbar1.png',
        text: '派名片',
        path: '',
      },
      {
        img: '/images/tabbar1.png',
        text: '推海报',
        path: '',
      },
      {
        img: '/images/tabbar1.png',
        text: '推好文',
        path: '',
      },
      {
        img: '/images/tabbar1.png',
        text: '团队任务',
        path: '',
      },
      {
        img: '/images/tabbar1.png',
        text: '销售日报',
        path: '',
      },
      {
        img: '/images/tabbar1.png',
        text: '日程管理',
        path: '',
      },
    ],
    // 海报
    poster:[
      {
        id:'0',
        img:'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
      },
      {
        id: '0',
        img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
      },
      {
        id: '0',
        img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
      },
      {
        id: '0',
        img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
      },
    ],
    // 推好文
    read:[
      {
        id:'0',
        img:'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
        title:'【健康养生】用金银花泡水喝有什么好处【健康养生】用金银花泡水喝有什么好处',
        text:'金银花茶的营养价值，金银花的茎，叶和花都可入药，具有解毒等多种功效。金银花茶的营养价值，金银花的茎，叶和花都可入药，具有解毒等多种功效。'
      },
      {
        id: '0',
        img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
        title: '【健康养生】用金银花泡水喝有什么好处',
        text: '金银花茶的营养价值，金银花的茎，叶和花都可入药，具有解毒等多种功效。'
      },
      {
        id: '0',
        img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
        title: '【健康养生】用金银花泡水喝有什么好处',
        text: '金银花茶的营养价值，金银花的茎，叶和花都可入药，具有解毒等多种功效。'
      },
    ],
    // 近期客户
    customers:[
      {
        time:'今天',
        list:[
          {
            id:'0',
            img:'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
            name:'姓名姓名',
            source:'私聊 名片皮诺客',
          },
          {
            id: '0',
            img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
            name: '姓名姓名',
            source: '私聊 公司皮诺客',
          },
        ],
      },
      {
        time: '18-11-25',
        list: [
          {
            id: '0',
            img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/poster.png',
            name: '姓名姓名',
            source: '主入口 公司',
          },
        ],
      },
    ],


    // 底部tabbar
    hasUnRead: true,
    tabbarIndex: 0,
    tabbar: [
      {
        img: '/images/manage1.png',
        imgSelect: '/images/manage1-select.png',
        text: '工作台',
        url: '/pages/manage1/manage1',
      },
      {
        img: '/images/manage2.png',
        imgSelect: '/images/manage2-select.png',
        text: '客户',
        url: '/pages/manage2/manage2',
      },
      {
        img: '/images/manage3.png',
        imgSelect: '/images/manage3-select.png',
        text: '消息',
        url: '/pages/manage3/manage3',
      },
      {
        img: '/images/manage4.png',
        imgSelect: '/images/manage4-select.png',
        text: '我',
        url: '/pages/manage4/manage4',
      },
    ],
  },
  tonav:function(e){
    var that = this;
    var path =e.currentTarget.dataset.path;
    if(path==''){
      wx.showToast({
        title: '功能尚未开放，敬请期待！',
        icon:'none'
      })
    }else{
      wx.navigateTo({
        url: path,
      })
    }
  },
  // 跳转到客户详情
  tocustomersDetail: function (e) {
    var cid = e.currentTarget.id;
    wx.navigateTo({
      url: '/pages/customersDetail/customersDetail?customerid='+cid,
    })
  },
  // 跳转对话
  tochats: function (e) {
    var id = e.currentTarget.id;
    wx.navigateTo({
      url: '/pages/chatManage/chatManage?cid='+id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中',
      icon: 'loading'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.siteInfo.managerpath+'manager_index1',
      method:"post",
      data:{
        mid:app.siteInfo.mid
      },
      success:function(res){
        that.setData({
          canArr:res.data.top,
          customers:res.data.bottom
        })
        app.siteInfo.pid = res.data.pid;
        var canArr = that.data.canArr;
        var colorArr = that.data.colorArr;
        for (var i = 0; i < canArr.length; i++) {
          var j = 3 * i + 1;
          var k = 3 * i + 2;
          var l = 3 * i + 3;
          var canArrNum = canArr[i].progress;
          var canColor = colorArr[i];

          var ctx1 = wx.createCanvasContext('canvas' + j)
          ctx1.beginPath()
          ctx1.arc(30, 30, 28, 0, 2 * Math.PI)
          ctx1.setFillStyle('#f0f0f0')
          ctx1.fill()
          ctx1.draw()
          var ctx2 = wx.createCanvasContext('canvas' + k)
          ctx2.beginPath()
          ctx2.arc(30, 30, 28, -0.5 * Math.PI, canArrNum * 2 * Math.PI - 0.5 * Math.PI)
          ctx2.setFillStyle(canColor)
          ctx2.fill()
          ctx2.draw()
          var ctx3 = wx.createCanvasContext('canvas' + l)
          ctx3.beginPath()
          ctx3.arc(30, 30, 25, 0, 2 * Math.PI)
          ctx3.setFillStyle('#272B56')
          ctx3.fill()
          ctx3.draw()
        }
        wx.hideLoading();
      }
    })


    
   

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})